package com.shujia.homework;

import org.junit.Test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Exer1 {


    // 使用List和Map存放多个图书信息，遍历并输出。其中商品属性：编号，名称，单价，出版社；使用商品编号作为Map中的key
    @Test
    public void test1() {
        List<Book> list = new ArrayList<>();
        Map<String, Book> map = new HashMap<>();

        Book b1 = new Book(/*添加参数*/);
        Book b2 = new Book(/*添加参数*/);
        Book b3 = new Book(/*添加参数*/);
        map.put(b1.getNo(), b1);
        map.put(b2.getNo(), b2);
        map.put(b3.getNo(), b3);

        for (String no : map.keySet()) {
            System.out.println(map.get(no));
        }


        list.add(new Book(/*添加参数*/));
        list.add(new Book(/*添加参数*/));
        list.add(new Book(/*添加参数*/));

        for (Book book : list) {
            System.out.println(book);
        }


    }


    public int getIndexofArray(float[] f) {
        int rtn = -1;
        float objf = 3.4F;// 3.4F;
        List list = null;
        for (int i = 0; i < f.length; i++) {// f.length
            list.add(f[i]);
        }
        for (int i = 0; i < list.size(); i++) {//空指针
            float tmp = (float) list.get(i);
            if (objf == tmp) {
                rtn = i;
            }
        }
        return rtn;
    }

    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        list.add("str1");
        list.add(2, "str2");
        String s = list.get(1);
        System.out.println(s);
    }
}
